var app = getApp(),
  common = require("../../common/common.js");
Page({
  data: {

  },
  // 开始考试
  // startTest(e) {
  //   let _t = this.data
  //   wx.redirectTo({
  //     url: '/xc_train/pages/online/test/test?name=' + _t.moduleName + '&type=3&t=' + _t.type + '&id=' + _t.id + '&min=' + _t.readyExam.minute + '&category_id=' + _t.category_id ,
  //   })
  // },

  startTest(e) {
    let _t = this.data
    wx.redirectTo({
      url: '/xc_train/pages/online/test/test?name=' + _t.readyExam.name + '&type=3&id=' + _t.readyExam.id + '&min=' + _t.readyExam.topic_time,
    })
  },

  onLoad: function(w) {
    console.log(app.userinfo)
    //let name = w.name
    let id = w.id
    let _t = this
    _t.startGetUserInfo(_t);
    //_t.readyToSubject(name, id, _t, w.type);
    _t.obtainTestPaper(id);
    // _t.setData({
    //   moduleName: name,
    //   id: id,
    //   type:w.type,
    //   category_id: w.category_id
    // })
  },
  // 一级 准备考试
  readyToSubject(name, id, _t, p) {
    p == 1 ? (name = 'category') : (name = 'type')
    app.util.request({
      url: 'entry/wxapp/exam',
      data: {
        name: name,
        cid: id
      },
      success: function(a) {
        console.log(a)
        _t.setData({
          readyExam: a.data.data
        })
      }
    })
  },

  //获取考试试卷
  obtainTestPaper(id){
    let _t = this;
    app.util.request({
      url: 'entry/wxapp/PaperDetails',
      data: {
        id: id
      },
      success: function (a) {
        console.log(a)
        _t.setData({
          readyExam: a.data.data
        })
      }
    })
  },

  // 获取用户信息
  startGetUserInfo($this) {
    wx.getUserInfo({
      withCredentials: true,
      success: function(res) {
        console.log(res)
        $this.setData({
          user: res.userInfo
        })
      }
    })
  },
  onReady: function() {

  },
  onShow: function() {

  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  }
})